package com.example.service.impl;

import com.example.entity.user.AccountUser;
import com.example.mapper.UserMapper;
import com.example.service.AccountService;
import jakarta.annotation.Resource;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {

    @Resource
    UserMapper mapper;

    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

    @Override
    public List<AccountUser> getAccountList() {
        return mapper.getAccountList();
    }

    @Override
    public String resetPasswordByUid(int uid) {
        String password = encoder.encode("123456");
        if (mapper.resetPasswordByUid(password, uid) > 0) {
            return null;
        } else {
            return "重置密码失败，请稍后重试";
        }
    }

    @Override
    public String deleteAccountByUid(int uid) {
        if (mapper.deleteAccountByUid(uid) > 0) {
            return null;
        } else {
            return "删除用户失败，请稍后重试";
        }
    }
}
